package com.ycd.gis.controller;

import java.util.List;

import com.ycd.gis.domain.GisDevelopProject;
import com.ycd.gis.service.IGisDevelopProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ycd.common.annotation.Log;
import com.ycd.common.enums.BusinessType;
import com.ycd.gis.domain.GisUserDeveloper;
import com.ycd.gis.service.IGisUserDeveloperService;
import com.ycd.common.core.controller.BaseController;
import com.ycd.common.core.domain.AjaxResult;
import com.ycd.common.utils.poi.ExcelUtil;
import com.ycd.common.core.page.TableDataInfo;

/**
 * develop_userController
 * 
 * @author ruoyi
 * @date 2021-11-29
 */
@Controller
@RequestMapping("/gis/develop_user")
public class GisUserDeveloperController extends BaseController
{
    private String prefix = "gis/develop_user";

    @Autowired
    private IGisUserDeveloperService gisUserDeveloperService;
    @Autowired
    private IGisDevelopProjectService gisDevelopProjectService;

    @RequiresPermissions("gis:develop_user:view")
    @GetMapping()
    public String develop_user()
    {
        return prefix + "/develop_user";
    }

    /**
     * 查询develop_user列表
     */
    @RequiresPermissions("gis:develop_user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GisUserDeveloper gisUserDeveloper)
    {
        startPage();
        List<GisUserDeveloper> list = gisUserDeveloperService.selectGisUserDeveloperList(gisUserDeveloper);
        return getDataTable(list);
    }

    /**
     *  根据用户Id查询用户的开发项目
     * @param userId
     * @param gisDevelopProject
     * @return
     */
    @PostMapping("/list/{userId}")
    @ResponseBody
    public TableDataInfo list(@PathVariable("userId") Long userId, GisDevelopProject gisDevelopProject)
    {
        startPage();
        gisDevelopProject.setUserId(userId);
        List<GisDevelopProject> list = gisDevelopProjectService.selectGisDevelopProjectList(gisDevelopProject);
        return getDataTable(list);
    }

    /**
     * 导出develop_user列表
     */
    @RequiresPermissions("gis:develop_user:export")
    @Log(title = "develop_user", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GisUserDeveloper gisUserDeveloper)
    {
        List<GisUserDeveloper> list = gisUserDeveloperService.selectGisUserDeveloperList(gisUserDeveloper);
        ExcelUtil<GisUserDeveloper> util = new ExcelUtil<GisUserDeveloper>(GisUserDeveloper.class);
        return util.exportExcel(list, "develop_user数据");
    }

    /**
     * 新增develop_user
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存develop_user
     */
    @RequiresPermissions("gis:develop_user:add")
    @Log(title = "develop_user", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GisUserDeveloper gisUserDeveloper)
    {
        return toAjax(gisUserDeveloperService.insertGisUserDeveloper(gisUserDeveloper));
    }

    /**
     * 修改develop_user
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GisUserDeveloper gisUserDeveloper = gisUserDeveloperService.selectGisUserDeveloperById(id);
        mmap.put("gisUserDeveloper", gisUserDeveloper);
        return prefix + "/edit";
    }

    /**
     * 修改保存develop_user
     */
    @RequiresPermissions("gis:develop_user:edit")
    @Log(title = "develop_user", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GisUserDeveloper gisUserDeveloper)
    {
        return toAjax(gisUserDeveloperService.updateGisUserDeveloper(gisUserDeveloper));
    }

    /**
     * 删除develop_user
     */
    @RequiresPermissions("gis:develop_user:remove")
    @Log(title = "develop_user", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gisUserDeveloperService.deleteGisUserDeveloperByIds(ids));
    }

    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long userId, ModelMap mmap){
        mmap.put("userId",userId);
        return prefix + "/detail";
    }
}
